Telegram Group & Telegram Channel
📍 How to: кэширование в Python с помощью flexicache

В Python удобно использовать декораторы для кэширования результатов функций и методов — как в оперативной памяти, так и во временных хранилищах вроде memcached. Один из наиболее гибких инструментов для этого — flexicache из библиотеки fastcore.

flexicache — это декоратор, который поддерживает:
• LRU-кэширование (удаление наименее используемых элементов),
• политику истечения кэша по времени — time_policy,
• инвалидирование кэша при изменении файла — mtime_policy.

➡️ Пример: time_policy
@flexicache(time_policy(0.1))
def random_func():
return randint(1, 1000)

assert random_func() == random_func()
sleep(0.2)
assert random_func() != random_func()


➡️ Пример: mtime_policy. Инвалидирование при изменении файла main.py
@flexicache(mtime_policy('main.py'))
def random_func():
return randint(1, 1000)

Path('main.py').touch() # обновление времени изменения


➡️ Пример: совмещение политик
@flexicache(time_policy(0.1), mtime_policy('main.py'))
def random_func():
return randint(1, 1000)


Кэш сбрасывается либо по времени, либо при обновлении файла — в зависимости от того, что произойдёт первым.

➡️ Пример: LRU-кэширование
@flexicache(maxsize=2)
def random_func(v):
return randint(1, 1000)

random_func(1)
random_func(2)
random_func(3) # результат для аргумента 1 будет удалён


➡️ Пример: удобный timed_cache. Для кэша с таймаутом и ограничением размера
from fastcore.xtras import timed_cache

@timed_cache(0.1, maxsize=2)
def random_func(v):
return randint(1, 1000)


📌 flexicache — гибкий и мощный инструмент для продвинутого кэширования в Python. Поддерживает политики истечения, комбинирование стратегий и заменяет стандартный lru_cache.

Библиотека питониста #буст
Please open Telegram to view this post
VIEW IN TELEGRAM



tg-me.com/pyproglib/6711
Create:
Last Update:

📍 How to: кэширование в Python с помощью flexicache

В Python удобно использовать декораторы для кэширования результатов функций и методов — как в оперативной памяти, так и во временных хранилищах вроде memcached. Один из наиболее гибких инструментов для этого — flexicache из библиотеки fastcore.

flexicache — это декоратор, который поддерживает:
• LRU-кэширование (удаление наименее используемых элементов),
• политику истечения кэша по времени — time_policy,
• инвалидирование кэша при изменении файла — mtime_policy.

➡️ Пример: time_policy

@flexicache(time_policy(0.1))
def random_func():
return randint(1, 1000)

assert random_func() == random_func()
sleep(0.2)
assert random_func() != random_func()


➡️ Пример: mtime_policy. Инвалидирование при изменении файла main.py
@flexicache(mtime_policy('main.py'))
def random_func():
return randint(1, 1000)

Path('main.py').touch() # обновление времени изменения


➡️ Пример: совмещение политик
@flexicache(time_policy(0.1), mtime_policy('main.py'))
def random_func():
return randint(1, 1000)


Кэш сбрасывается либо по времени, либо при обновлении файла — в зависимости от того, что произойдёт первым.

➡️ Пример: LRU-кэширование
@flexicache(maxsize=2)
def random_func(v):
return randint(1, 1000)

random_func(1)
random_func(2)
random_func(3) # результат для аргумента 1 будет удалён


➡️ Пример: удобный timed_cache. Для кэша с таймаутом и ограничением размера
from fastcore.xtras import timed_cache

@timed_cache(0.1, maxsize=2)
def random_func(v):
return randint(1, 1000)


📌 flexicache — гибкий и мощный инструмент для продвинутого кэширования в Python. Поддерживает политики истечения, комбинирование стратегий и заменяет стандартный lru_cache.

Библиотека питониста #буст

BY Библиотека питониста | Python, Django, Flask




Share with your friend now:
tg-me.com/pyproglib/6711

View MORE
Open in Telegram


Библиотека питониста | Python Django Flask Telegram | DID YOU KNOW?

Date: |

How to Use Bitcoin?

n the U.S. people generally use Bitcoin as an alternative investment, helping diversify a portfolio apart from stocks and bonds. You can also use Bitcoin to make purchases, but the number of vendors that accept the cryptocurrency is still limited. Big companies that accept Bitcoin include Overstock, AT&T and Twitch. You may also find that some small local retailers or certain websites take Bitcoin, but you’ll have to do some digging. That said, PayPal has announced that it will enable cryptocurrency as a funding source for purchases this year, financing purchases by automatically converting crypto holdings to fiat currency for users. “They have 346 million users and they’re connected to 26 million merchants,” says Spencer Montgomery, founder of Uinta Crypto Consulting. “It’s huge.”

What is Telegram?

Telegram’s stand out feature is its encryption scheme that keeps messages and media secure in transit. The scheme is known as MTProto and is based on 256-bit AES encryption, RSA encryption, and Diffie-Hellman key exchange. The result of this complicated and technical-sounding jargon? A messaging service that claims to keep your data safe.Why do we say claims? When dealing with security, you always want to leave room for scrutiny, and a few cryptography experts have criticized the system. Overall, any level of encryption is better than none, but a level of discretion should always be observed with any online connected system, even Telegram.

Библиотека питониста | Python Django Flask from vn


Telegram Библиотека питониста | Python, Django, Flask
FROM USA